//
//  searchResultListViewController.m
//  有材网
//
//  Created by qijia on 16/1/21.
//  Copyright © 2016年 肖扬. All rights reserved.
//

#import "searchResultListView.h"
#import "QJCellConfig.h"
#import "homeModel.h"
#import "MySaveModel.h"
#import "homeModel.h"
#import "homeVCCell.h"
#import "OrderNullView.h"
#import "searchResultViewCell.h"
@interface searchResultListView (){
    int Page;
}
@property (nonatomic,strong) OrderNullView *nullView;
@end

@implementation searchResultListView
@synthesize hisList,delegate,text,nullView;
-(void)drawRect:(CGRect)rect{
    
}

-(void)makeSeachData:(id)data{
    Page = 1;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.frame = CGRectMake(0, 0, kWIDTH, VHEIGHT);
    m_tableView = [[QJUIMapping mapping] tableControlWithTableView:self.tableView withDelegate:self withContainer:self];
    [m_tableView goDown:YES withUp:YES beginRefreshing:YES];
    [self addSubview:self.tableView];
    [self initDataWithControl:m_tableView];
}

-(void)initDataWithControl:(QJTableView *)control{
    [self.cellArray removeAllObjects];
    [self.cellArray addObjectsFromArray:[QJCellConfig arrayFromDataArray:hisList className:@"searchResultViewCell"]];
    [self reloadDatas];
    if (hisList.count!=0) {
        [nullView setHidden:YES];
    }else{
        if (!nullView) {
            self.nullView = [[OrderNullView alloc]initWithFrame:CGRectMake(0, 0, SWIDTH, VHEIGHT)];
            nullView.backgroundColor = [UIColor clearColor];
            [nullView setHidden:NO];
            [self addSubview:nullView];
        }else{
            [nullView setHidden:NO];
        }
    }
}
-(NSMutableArray *)hot_keyword{
    TIME
    HEADDIC(nowTime, SEARCHLIST);
    NSMutableDictionary *body = [NSMutableDictionary dictionary];
    [body setObject:self.text forKey:@"keyword"];
    [body setObject:[NSNumber numberWithInt:1] forKey:@"page"];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:HEAD forKey:@"head"];
    [dic setObject:body forKey:@"body"];
    requestManage *request = [[requestManage alloc]init];
    NSString *result = [request post:APPIP postDataDic:dic error:nil];
    NSLog(@"result__%@",result);
    MySaveModel *model = [[MySaveModel alloc]init];
    [model parseResponseData:result];
    return model.list;
}
-(void)onGoUpWithControl:(id)control{
    NSLog(@"上拉");
    Page++;
    NSMutableArray *arr = [self hot_keyword];
    if ([arr count]!=0) {
        [hisList addObjectsFromArray:arr];
    }
    [self reloadDatas];
}
-(void)onGoDownWithControl:(id)control{
    NSLog(@"下拉");
    Page = 1;
    [hisList removeAllObjects];
    NSMutableArray *arr = [self hot_keyword];
    [hisList addObjectsFromArray:arr];
    [self reloadDatas];
}
-(void)onGoCellSelect:(NSIndexPath *)indexPath withObject:(id)object withControl:(id)control{
    NSLog(@"index___%d__object__%@___control___%@",indexPath.section,object,control);
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(pushDetailsVC:)]) {
        homeModelSupply *model = [hisList objectAtIndex:indexPath.section];
        [self.delegate pushDetailsVC:model];
    }
}
@end
